package com.ustropo.financas.conta;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.ustropo.financas.R;

/**
 * Classe adaptadora para mostrar uma lista de Contas
 * 
 * @author Fernando C. de Souza
 * @version 1.0
 * @since 31/10/2013
 */
public class ContaAdapter extends ArrayAdapter<IConta> {

	/* variaveis */
	private List<IConta> contas;
	private Context context;
	
	/**
	 * 
	 * @param context
	 * @param contas
	 */
	public ContaAdapter(Context context, List<IConta> contas) {
		super(context, R.layout.simple_list_item);
		this.contas = contas;
		this.context = context;
	}

	/*
	 * (non-Javadoc)
	 * @see android.widget.ArrayAdapter#getCount()
	 */
	@Override
	public int getCount(){
		return contas.size();
	}
	
	/*
	 * (non-Javadoc)
	 * @see android.widget.ArrayAdapter#getView(int, android.view.View, android.view.ViewGroup)
	 */
	@Override
	public View getView(int position, View convertView, ViewGroup parent){
		View rowView = convertView;
		if(rowView == null) {
			LayoutInflater inflater = (LayoutInflater) 
					context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			// Layout
			rowView = inflater.inflate(R.layout.simple_list_item, parent, false);
		}
		
		IConta conta = contas.get(position);
		TextView line = (TextView) rowView.findViewById(R.id.descricao);
		
		line.setText(conta.getNome());
		
		return rowView;
	}

}
